xend: Implement auto-ballooning for Solaris.
authorKeir Fraser <keir@xensource.com>
Sat, 31 Mar 2007 13:05:57 +0000 (14:05 +0100)
committerKeir Fraser <keir@xensource.com>
Sat, 31 Mar 2007 13:05:57 +0000 (14:05 +0100)
/proc/xen/balloon is Linux-specific. Implement a Solaris backend
too. Also fix the FMRI for xend.

Signed-off-by: Ryan Scott <ryan.scott@sun.com>
tools/python/xen/lowlevel/scf/scf.c
tools/python/xen/xend/balloon.py
tools/python/xen/xend/osdep.py

index a73ac2041969bcf42a088ad2c00841ff21794795..0e205179b605c80d519acbb0a3cd438d05dcf1af 100644 (file)
@@ -26,7 +26,7 @@
 #include <libscf.h>
 #include <stdio.h>
 
-#define        XEND_FMRI "svc:/system/xen/xend:default"
+#define        XEND_FMRI "svc:/system/xctl/xend:default"
 #define        XEND_PG "config"
 
 static PyObject *scf_exc;
index e7c2693ab32bd8a1f5df83770be774feaad70857..ff051da88e92e051da30a26c3460ab28d6f5c26f 100644 (file)
@@ -25,9 +25,7 @@ import XendDomain
 import XendOptions
 from XendLogging import log
 from XendError import VmError
-
-
-PROC_XEN_BALLOON = '/proc/xen/balloon'
+import osdep
 
 RETRY_LIMIT = 20
 RETRY_LIMIT_INCR = 5
@@ -51,19 +49,7 @@ def _get_proc_balloon(label):
     """Returns the value for the named label.  Returns None if the label was
        not found or the value was non-numeric."""
 
-    f = file(PROC_XEN_BALLOON, 'r')
-    try:
-        for line in f:
-            keyvalue = line.split(':')
-            if keyvalue[0] == label:
-                values = keyvalue[1].split()
-                if values[0].isdigit():
-                    return int(values[0])
-                else:
-                    return None
-        return None
-    finally:
-        f.close()
+    return osdep.lookup_balloon_stat(label)
 
 def get_dom0_current_alloc():
     """Returns the current memory allocation (in KiB) of dom0."""
index 2136465ea7931dc7df1996e59b541226ac734e56..b3abbf782b6909f07541320aea2b223ec1313507 100644 (file)
@@ -41,6 +41,55 @@ _vif_script = {
     "SunOS": "vif-vnic"
 }
 
+def _linux_balloon_stat(label):
+    """Returns the value for the named label, or None if an error occurs."""
+
+    PROC_XEN_BALLOON = '/proc/xen/balloon'
+    f = file(PROC_XEN_BALLOON, 'r')
+    try:
+        for line in f:
+            keyvalue = line.split(':')
+            if keyvalue[0] == label:
+                values = keyvalue[1].split()
+                if values[0].isdigit():
+                    return int(values[0])
+                else:
+                    return None
+        return None
+    finally:
+        f.close()
+
+def _solaris_balloon_stat(label):
+    """Returns the value for the named label, or None if an error occurs."""
+
+    import fcntl
+    import array
+    DEV_XEN_BALLOON = '/dev/xen/balloon'
+    BLN_IOCTL_CURRENT = 0x4201
+    BLN_IOCTL_TARGET = 0x4202
+    BLN_IOCTL_LOW = 0x4203
+    BLN_IOCTL_HIGH = 0x4204
+    BLN_IOCTL_LIMIT = 0x4205
+    label_to_ioctl = { 'Current allocation'    : BLN_IOCTL_CURRENT,
+                       'Requested target'      : BLN_IOCTL_TARGET,
+                       'Low-mem balloon'       : BLN_IOCTL_LOW,
+                       'High-mem balloon'      : BLN_IOCTL_HIGH,
+                       'Xen hard limit'        : BLN_IOCTL_LIMIT }
+
+    f = file(DEV_XEN_BALLOON, 'r')
+    try:
+        values = array.array('L', [0])
+        if fcntl.ioctl(f.fileno(), label_to_ioctl[label], values, 1) == 0:
+            return values[0]
+        else:
+            return None
+    finally:
+        f.close()
+
+_balloon_stat = {
+    "SunOS": _solaris_balloon_stat
+}
+
 def _get(var, default=None):
     return var.get(os.uname()[0], default)
 
@@ -49,3 +98,4 @@ xend_autorestart = _get(_xend_autorestart)
 pygrub_path = _get(_pygrub_path, "/usr/bin/pygrub")
 netback_type = _get(_netback_type, "netfront")
 vif_script = _get(_vif_script, "vif-bridge")
+lookup_balloon_stat = _get(_balloon_stat, _linux_balloon_stat)